import threading as td
import time, os

def job(x,y, f):
    for i in range(x,y):
        time.sleep(0.001)
        f.write(str(i) + '\n')

def start(f, is_multi_thread = True):
    if is_multi_thread:
        threads = []
        for i in range(10):
            t = td.Thread(target=job, args=(100*i+1,(i+1)*100+1, f))
            #t.daemon = True
            threads.append(t)
            t.start()
        [i.join() for i in threads]
    else:
        t = td.Thread(target=job, args=(1, 1001, f))
        t.start()
        t.join()

def multithread():
    time1 = time.time()
    file_path = r'C:\Users\Administrator\Desktop\cc.txt'
    if os.path.exists(file_path):
        os.remove(file_path)
    with open(r'C:\Users\Administrator\Desktop\cc.txt', 'a+') as book:
        start(book)
    time2 = time.time()
    print(time2 - time1)

def singlethread():
    time1 = time.time()
    with open(r'C:\Users\Administrator\Desktop\zz.txt', 'w') as book:
        start(book, False)
    time2 = time.time()
    print(time2 - time1)

singlethread()
multithread()
